package org.secangkirkopipanas.gxtcore.server.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import net.sf.hibernate4gwt.pojo.java5.LazyPojo;

import org.secangkirkopipanas.gxtcore.domain.ISystemUser;

@Entity
@Table(name = "sys_user")
public class SystemUser extends LazyPojo implements Serializable, ISystemUser {

	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "username", length = 25, nullable = false, insertable = true, updatable = true)
	private String username;

	@Column(name = "pwd_digest", length = 64, nullable = false, insertable = true, updatable = true)
	private String pwdDigest;

	@Column(name = "firstname", length = 25, nullable = false, insertable = true, updatable = true)
	private String firstname;

	@Column(name = "lastname", length = 25, nullable = false, insertable = true, updatable = true)
	private String lastname;

	@ManyToOne(targetEntity = SystemGroup.class)
	@JoinColumn(referencedColumnName = "id", nullable = false)
	private SystemGroup group;

	@Column(name = "title", length = 10, nullable = false, insertable = true, updatable = true)
	private String title;

	@Column(name = "work_location", length = 50, nullable = false, insertable = true, updatable = true)
	private String workLocation;

	@Column(name = "work_phone_number", length = 15, nullable = false, insertable = true, updatable = true)
	private String workPhoneNumber;

	@Column(name = "last_login_date", nullable = false, insertable = true, updatable = true)
	private Date lastLoginDate;

	@Column(name = "last_login_address", length = 50, nullable = false, insertable = true, updatable = true)
	private String lastLoginAddress;

	@Column(name = "is_locked", nullable = true, insertable = true, updatable = true)
	private boolean locked = false;

	public SystemUser() {
		super();
	}

	public SystemUser(String userId) {
		super();
		this.username = userId;
	}

	public SystemUser(String username, String pwdDigest, String firstname,
			String lastname, SystemGroup group, String title,
			String workLocation, String workPhoneNumber, Date lastLoginDate,
			String lastLoginAddress, boolean locked) {
		super();
		this.username = username;
		this.pwdDigest = pwdDigest;
		this.firstname = firstname;
		this.lastname = lastname;
		this.group = group;
		this.title = title;
		this.workLocation = workLocation;
		this.workPhoneNumber = workPhoneNumber;
		this.lastLoginDate = lastLoginDate;
		this.lastLoginAddress = lastLoginAddress;
		this.locked = locked;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPwdDigest() {
		return pwdDigest;
	}

	public void setPwdDigest(String pwdDigest) {
		this.pwdDigest = pwdDigest;
	}

	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public SystemGroup getGroup() {
		return group;
	}

	public void setGroup(SystemGroup group) {
		this.group = group;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getWorkLocation() {
		return workLocation;
	}

	public void setWorkLocation(String workLocation) {
		this.workLocation = workLocation;
	}

	public String getWorkPhoneNumber() {
		return workPhoneNumber;
	}

	public void setWorkPhoneNumber(String workPhoneNumber) {
		this.workPhoneNumber = workPhoneNumber;
	}

	public Date getLastLoginDate() {
		return lastLoginDate;
	}

	public void setLastLoginDate(Date lastLoginDate) {
		this.lastLoginDate = lastLoginDate;
	}

	public String getLastLoginAddress() {
		return lastLoginAddress;
	}

	public void setLastLoginAddress(String lastLoginAddress) {
		this.lastLoginAddress = lastLoginAddress;
	}

	public boolean isLocked() {
		return locked;
	}

	public void setLocked(boolean locked) {
		this.locked = locked;
	}

	public boolean isSystemAdmin() {
		return (SystemGroup.SYSADMIN_GROUP_ID == group.getId());
	}

}